/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package model;

import com.google.inject.Inject;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.Queue;

/**
 *
 * @author think
 */
public class CmdResultManager {

    @Inject ConfigManager configManager;

    private  Queue<Executable> msgQueue = new LinkedList<Executable>();
    private  Queue<Executable> recent = new LinkedList();

    public  void addResult(Executable cmd) {
        msgQueue.add(cmd);
//        if(history.size()>=10)
        if (recent.size() >= configManager.getShowCmdHistoryCount()) {
            recent.poll();
        }
        recent.add(cmd);
    }

    public  Command getResult() {
        Command cmd = (Command) msgQueue.poll();
        return cmd;
    }

    //Should display the most recent command result at top.
    public  Executable[] getRecentCmdResults() {
//        System.out.println(history.size());
        Executable[] commands = new Executable[recent.size()];
        Iterator it = recent.iterator();
        int index = commands.length - 1;
        while (it.hasNext()) {
            Executable cmd = (Executable) it.next();
            commands[index--] = cmd;
        }
        return commands;
    }

    public  int getQueuedResultsCount() {
        return msgQueue.size();
    }

//    public static String[] getAllResults(){
//        String[] allMsgs = new String[msgQueue.size()];
//        int index = 0;
//        while(msgQueue.size()>0){
//            allMsgs[index++] = (String)msgQueue.poll();
//        }
//        return allMsgs;
//    }
    public  void reset() {
        msgQueue.clear();
        recent.clear();
    }
}
